package com.superm.service.impl;

import com.superm.entity.Emp;
import com.superm.entity.Role;
import com.superm.mappers.EmpDutiesMapper;
import com.superm.service.EmpDutiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户角色实现类
 */
@Service
public class EmpDutiesServiceImpl implements EmpDutiesService {
    @Autowired
    private EmpDutiesMapper empDutiesMapper;
    @Override
    public Integer queryIds(List<String> rids) {
        return empDutiesMapper.queryIds(rids);
    }



    /**
     * 添加用户角色
     * @param
     * @return
     */
    @Override
    public int addEmpRole(Integer[] listRole,Integer eId){
        Emp emp = new Emp();
        List<Role> listRoles = new ArrayList<Role>();
        emp.seteId(eId);
        //循环添加的用户编号集合
        for (int i = 0;i<listRole.length;i++){
            //编号添加到role集合对象
            Role role = new Role();
            role.setRid(listRole[i]);
            listRoles.add(role);
        }
        //多个角色信息添加到用户
        emp.setRoles(listRoles);
        return empDutiesMapper.addInfoMation(emp);
    }

    /**
     * 删除用户角色信息
     * @param listRole
     * @param eId
     * @return
     */
    @Override
    public int deleteEmpRole(Integer[] listRole, Integer eId) {

        Emp emp = new Emp();
        List<Role> listRoles = new ArrayList<Role>();
        emp.seteId(eId);
        //循环添加的用户编号集合
        for (int i = 0;i<listRole.length;i++){
            System.out.println(listRole[i]);
            System.out.println("用户:"+eId);
            //编号添加到role集合对象
            Role role = new Role();
            role.setRid(listRole[i]);
            listRoles.add(role);
        }
        //多个角色信息添加到用户
        emp.setRoles(listRoles);
        return empDutiesMapper.deleteInfoMation(emp);
    }

    /**
     * 实现查询条数
     * @param eId
     * @return
     */
    @Override
    public int selectEmpRoleCount(Integer eId){
        return empDutiesMapper.selectInfoMationCount(eId);
    }


}
